package com.bwie.redkids.adapter;

import java.util.ArrayList;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.CartBean;
import com.lidroid.xutils.BitmapUtils;
import com.tencent.connect.a.a;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class ShoppingListBaseAdapter extends BaseAdapter {

	private ArrayList<CartBean> arrayList;
	private Context context;

	public ShoppingListBaseAdapter(Context context,
			ArrayList<CartBean> arrayList) {
		this.context = context;
		this.arrayList = arrayList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Holder holder;
		final CartBean cart = arrayList.get(position);
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.shopping_list_item,
					null);
			holder = new Holder();
			holder.imageIcon = (ImageView) convertView
					.findViewById(R.id.ima_icon);
			holder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
			holder.tvPrice = (TextView) convertView.findViewById(R.id.tv_price);
			holder.tvNum = (TextView) convertView.findViewById(R.id.tv_num);
			// 增加
			holder.popAdd = (TextView) convertView.findViewById(R.id.pop_add);
			// 减少
			holder.popReduce = (TextView) convertView
					.findViewById(R.id.pop_reduce);
			// 商品数量
			holder.tvNumber = (TextView) convertView
					.findViewById(R.id.tvNumber);
			// 按钮
			holder.che = (CheckBox) convertView.findViewById(R.id.che);
			// 删除按钮
			holder.butDel = (Button) convertView.findViewById(R.id.but_del);
			// 绑定资源
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		BitmapUtils bitmapUtils = new BitmapUtils(context);
		bitmapUtils.display(holder.imageIcon, arrayList.get(position)
				.getImageurl());
		holder.tvName.setText(arrayList.get(position).getName());
		holder.tvPrice.setText(arrayList.get(position).getPrice() + "");
		return convertView;
	}

	class Holder {
		ImageView imageIcon;
		TextView tvName, tvPrice, tvNum, popReduce, popAdd, tvNumber;
		CheckBox che;
		Button butDel;
	}

}
